package com.hangwei.paperless.view.window;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.RelativeLayout;

import com.hangwei.paperless.MainSeeActivity;
import com.hangwei.paperless.R;
import com.hangwei.paperless.adapter.FinalAdapter;
import com.hangwei.paperless.model.bean.MainRepairList;
import com.hangwei.paperless.model.bean.RecordListBean;
import com.hangwei.paperless.presenter.MainSeePresenter;
import com.hangwei.paperless.view.BaseView;
import com.hangwei.paperless.view.SealHelper;
import com.twelve.all.net.CallBack;
import com.twelve.all.utils.LoadingDialog;
import com.twelve.all.utils.Tools;

/**
 * Created by 张龙臣 on 2020/11/24.
 */

public class FinalCheckSee extends BaseView<MainSeeActivity, RecordListBean> {

    private EditText mEtRemark;
    private RelativeLayout mRlInspectorSeal;

    public FinalCheckSee(MainSeeActivity activity) {
        super(activity);
    }

    @Override
    protected View initView() {
        View inflate = LayoutInflater.from(mActivity).inflate(R.layout.page_see_final_check, null);
        mEtRemark = inflate.findViewById(R.id.etRemark);
        mRlInspectorSeal = inflate.findViewById(R.id.rlInspectorSeal);
        inflate.findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mActivity.finish();
            }
        });
        RecyclerView recyclerView = inflate.findViewById(R.id.recyclerView);
        SwipeRefreshLayout refreshLayout = inflate.findViewById(R.id.refreshLayout);
        FinalAdapter adapter = new FinalAdapter(null) {
            @Override
            protected void seal(RecordListBean item, int stampRole, String resultVal) {

            }
        };
        adapter.setEnableAll(false);
        adapter.addFooterView(getFootView());
        MainSeePresenter presenter = new MainSeePresenter(refreshLayout, adapter, recyclerView);
        presenter.setBillId(mActivity.getBillId());
        presenter.setPage(8);
        recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
        recyclerView.setAdapter(adapter);
        final LoadingDialog loadingDialog = new LoadingDialog(mActivity);
        loadingDialog.show();
        presenter.refresh(new CallBack<MainRepairList>() {
            @Override
            public void onCompleted(MainRepairList info) {
                loadingDialog.dismiss();
                if (info!=null){
                    mEtRemark.setText(Tools.checkedString(info.remark));
                    SealHelper sealHelper = new SealHelper(mActivity) {
                        @Override
                        protected void onSeal() {
                        }
                    };
                    sealHelper.bindData(new SealHelper.SealBean(true,info.inspectorStampId,info.inspectorId,info.inspectorStampTypeCode,info.inspectorStampCode,info.inspectorDate,info.inspector,false));
                    mRlInspectorSeal.removeAllViews();
                    mRlInspectorSeal.addView(sealHelper.getItemView());
                }
            }

            @Override
            public void onError() {
                loadingDialog.dismiss();
            }
        });
        return inflate;
    }

    private View getFootView() {
        View inflate = LayoutInflater.from(mActivity).inflate(R.layout.footer_final, null);
        mEtRemark = inflate.findViewById(R.id.etRemark);
        mRlInspectorSeal = inflate.findViewById(R.id.rlInspectorSeal);
        return inflate;
    }
}
